﻿using App;
using App.Cache;
using App.Extension;
using App.Handle;
using App.MessageExtension;
using App.Pipeline;
using App.Schedule;
using Newtonsoft.Json;
using Simple.BasicNet.Core;
using Simple.BasicNet.Core.Configuration;
using Simple.BasicNet.Core.Handle;
using Simple.BasicNet.Core.Net;
using Simple.BasicNet.Core.Pipeline;
using Simple.WindowsServer;
using System.Threading;

public class Program
{
	private static ManualResetEvent mre = new ManualResetEvent(false);
	NLog.ILogger logger;
	public static int Main(string[] args)
	{
		
		//CancellationToken cancellation= new CancellationToken();
		
		//Task.Run(() =>
		//{
		//	int i = 0;
		//	while (true)
		//	{
		//		i++;
		//		if (i==10)
		//		{
		//			break;
					
		//		}
		//		Console.WriteLine(i);
		//	}
		//},cancellation).Wait();

		IHost host = Host.BuilderHost().Regster((container) =>
		{
			//容器模块，注册需要实例的对象，容器可以自动创建对象，解决对象的依赖。
			container.RegisterSingleton<IMessageHandle, IDTMessageHandle>();
			container.Register<IContext, IDTContext>();
			container.RegisterSingleton<IRedisClientService, RedisClientService>();
			container.Register<VersionUpgradeHanlder>();
			container.RegisterSingleton<IConfiguration, IDTConfiguration>();
		}).
		RegisterSchedule((scheduleManager) =>
		{
			//注册任务
			//任务是固定时间间隔执行
			//一个任务周期为 任务中逻辑时间+等待时间
			//通常任务时间比较少，适合做心跳检查
			//scheduleManager.Register<TestSchedule>();
			scheduleManager.Register<CheckHeartSchedule>();
			scheduleManager.Register<CheckCommandSchedule>();

		}).Start<IDTConfiguration>()
		//.Start((configution) =>
		//{
		//	configution.Port = 7155;
		//	configution.Backlog = 200;
		//	configution.ProtocolType=System.Net.Sockets.ProtocolType.Tcp;
		//	configution.SetIpAddress("192.168.0.154");
		//	configution.SocketType = System.Net.Sockets.SocketType.Stream;
		//	IDTConfiguration cfg = configution.GetConfiguration<IDTConfiguration>();
		//	cfg.SignalRServerAddress = "http://127.0.0.1:60313/signalr/dtm";
		//	cfg.ApiAddress = "http://127.0.0.1:7125";
		//	cfg.RedisConnection = "127.0.0.1:6379,password=123456,defaultDatabase=15,poolsize=50,connectTimeout=5000,syncTimeout=10000";
		//	// cfg.ApiAddress = "http://172.16.1.128:7125";
		//	// cfg.SignalRServerAddress = "http://172.16.1.128:9003/signalr/dtm";
		//})
		.ConfigutionPipeline((host) =>
		{
			host.ConfigutionPipeline<VerifyPipeline>();
			host.ConfigutionPipeline<AuthenticationPipeLine>();
		}).UseWindowsService();
		Console.ReadLine();
		//Type type=typeof(AHandle);
		//FindBaseHandleChildren find = new FindBaseHandleChildren();
		//while (true)
		//{
		//	string strCommand = Console.ReadLine();
		//	int.TryParse(strCommand,out int number);

		//	find.Find(number);
		//	if (number==0)
		//	{
		//		break;
		//	}
		//}
		return 0;
	}
	private static void ThreadProc()
	{
		string name = Thread.CurrentThread.Name;

		Console.WriteLine(name + " starts and calls mre.WaitOne()");

		mre.WaitOne();

		Console.WriteLine(name + " ends.");
	}
}
